/*
 * Copyright (c) 2005, 2014 vacoor
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package org.vacoor.nothing.security.logging.jul;

import org.vacoor.nothing.security.logging.LoggerInfo;

import java.util.logging.Level;
import java.util.logging.Logger;

public class JulInfo extends LoggerInfo {
    private static final Level[] LEVELS = {null, Level.FINEST, Level.FINE, Level.CONFIG, Level.INFO, Level.WARNING, Level.SEVERE, Level.OFF};

    final Logger logger;

    public JulInfo(String name, Logger logger) {
        super(name);
        this.logger = logger;
    }

    public String getLevel() {
        if (this.logger == null) {
            return null;
        }

        Level level = this.logger.getLevel();

        if (level != null) {
            return level.getName();
        }
        for (Level l : LEVELS)
            if (l != null) {
                if (this.logger.isLoggable(l)) {
                    return l.getName();
                }
            }
        return Level.OFF.getName();
    }

    public boolean isSet() {
        return (this.logger != null) && (this.logger.getLevel() != null);
    }
}